// JavaScript Document
//----------------------------------------员工信息模块-------------------
//员工信息Ajax通道
function ajaxWorker(fun_type,data){
	loading();
	switch(fun_type){
		case "viewInfo":
			$.get("../AjaxWorker/doAjax?fun_type=viewInfo",null,function(data){
				$("#div-info-table").html(data);
				$(".li-worker").css("background-color","#9CF");
				$("#li-worker-info").css("background-color","#666");
				disLoading();
			}).fail(function(){alert("Worker ajax is faild!")});
		break;
		
		case "editInfo":
			$.get("../AjaxWorker/doAjax?fun_type=editInfo&name="+data[0]+"&sex="+data[1]+"&birthday="+data[2]+"&email="+data[3]+"&branch="+data[4]+"&phonenum="+
			data[5]+"&banknum="+data[6]+"&bank="+data[7]+"&entryday="+data[8]+"&leaveday="+data[9]+"&persionid="+data[10],null,function(){
				ajaxWorker("viewInfo",null);
				$("#div-mask-3").css("height",'0');
			}).fail(function(){alert("Worker ajax is failed!");});
		break;
		
		case "viewFile":
			$.get("../AjaxWorker/doAjax?fun_type=viewFile",null,function(data){
				$("#div-info-table").html(data);
				$(".li-worker").css("background-color","#9CF");
				$("#li-worker-file").css("background-color","#666");
				disLoading();
			}).fail(function(){alert("Worker ajax is faild!")});
		break;
		
		case "deleteFile":
			$.get("../AjaxWorker/doAjax?fun_type=deleteFile&filename="+data[0],null,function(data){
				alert(data);
				ajaxWorker("viewFile",null);
				disLoading();
			}).fail(function(){alert("Delete ajax was failed!")});
		break;
		
		case "adminPanel":
			$.get("../AjaxWorker/doAjax?fun_type=adminPage",null,function(data){
				if(data == "error"){alert("权限拒绝");}
				else{
					$("#div-info-table").html(data);
					$(".li-worker").css("background-color","#9CF");
					$("#li-worker-admin").css("background-color","#666");
				}
				disLoading();
			}).fail(function(){alert("adminPage ajax is failed")});
		break;
		
		case "adminEdit":
			$.get("../AjaxWorker/doAjax?fun_type=adminEdit&workerid="+data[0]+"&name="+data[1]+"&birthday="+data[2]+"&email="+data[3]+"&branch="+data[4]+
			"&phonenum="+data[5]+"&banknum="+data[6]+"&bank="+data[7]+"&entryday="+data[8]+"&leaveday="+data[9]+"&persionid="+data[10],null,function(data){
				$("#div-mask-3").css("height","0");
				ajaxWorker("adminPage",null);
				disLoading();
			}).fail(function(){alert("adminEdit ajax was failed!")});
		break;
		
		case "adminFile":
			$.get("../AjaxWorker/doAjax?fun_type=adminFile&workerid="+data[0],null,function(data){
				$("#div-mask-5").html(data).css("height",$(document).height()+'px');
				disLoading();
			}).fail(function(){alert("adminFile ajax was failed!")});
		break;
	}
}
//头像panel操作
function enFaceimgPanel(){$("#div-mask-6").css("height",$(document).height()+'px');}
function disFaceimgPanel(){$("#div-mask-6").css("height",0);}

//worker工作区切换
function workerPanel(){
	workerSpace = "Worker";
	ajaxWorker("viewInfo",null);
	$("#li-worker").css("border-top","#000 3px solid");
	$("#li-itw").css("border","0");
	$("#li-dev").css("border","0");
	$(".li-itw").css("display","none");
	$(".li-dev").css("display","none");
	$(".li-worker").css("display","block");
	$("#div-page").css("display","none");
}
//admin查看附件
function adminFile(workerid){
	var data = new Array(workerid);
	ajaxWorker("adminFile",data);
}
//取消admin查看附件
function disAdminFile(){
	$("#div-mask-5").css("height",0);
}
//打开信息修改
function editWorkerInfo(){
	$("#div-mask-3").css("height",$(window).height()+'px');
	$("#button-edit-worker").css("display","inline");$("#button-edit-admin").css("display","none");
	$('[name = "worker-name"]').val("{$Think.session.iry_worker_name}");
	$('[name = "worker-birthday"]').val("{$Think.session.iry_worker_birthday}");
	$('[name = "worker-email"]').val("{$Think.session.iry_worker_email}");
	$('[name = "worker-phonenum"]').val("{$Think.session.iry_worker_phonenum}");
	$('[name = "worker-branch"]').val("{$Think.session.iry_worker_branch}");
	$('[name = "worker-banknum"]').val("{$Think.session.iry_worker_banknum}");
	$('[name = "worker-bank"]').val("{$Think.session.iry_worker_bank}");
	$('[name = "worker-entryday"]').val("{$Think.session.iry_worker_entryday}");
	$('[name = "worker-leaveday"]').val("{$Think.session.iry_worker_leaveday}");
	$('[name = "worker-persionid"]').val("{$Think.session.iry_worker_persionid}");
}
//取消信息编辑
$("#reset-edit-worker").click(function(){$("#div-mask-3").css("height","0");});

//提交修改信息
$("#button-edit-worker").click(function(){
	var name = $('[name="worker-name"]').val();
	var sexgroup = document.getElementsByName("worker-sex");
	for(var i = 0; i<sexgroup.length; i++){
		if(sexgroup.item(i).checked) sex=sexgroup.item(i).value;
	}
	var birthday = $('[name = "worker-birthday"]').val();
	var email = $('[name = "worker-email"]').val();
	var branch = $('[name = "worker-branch"]').val();
	var phonenum = $('[name = "worker-phonenum"]').val();
	var banknum = $('[name = "worker-banknum"]').val();
	var bank = $('[name = "worker-bank"]').val();
	var entryday = $('[name = "worker-entryday"]').val();
	var leaveday = $('[name = "worker-leaveday"]').val();
	var persionid = $('[name = "worker-persionid"]').val();
	
	var infoArray = new Array(name,sex,birthday,email,branch,phonenum,banknum,bank,entryday,leaveday,persionid);
	ajaxWorker("editInfo",infoArray);
});
//后台管理详情信息获取
function adminDetail(workerInfo){
	workerInfo = workerInfo.split(":");
	$("#div-mask-3").css("height",$(window).height()+'px');
	$("#button-edit-worker").css("display","none");$("#button-edit-admin").css("display","inline");
	$('[name = "worker-name"]').val(workerInfo[1]);
	$('[name = "worker-birthday"]').val(workerInfo[3]);
	$('[name = "worker-email"]').val(workerInfo[5]);
	$('[name = "worker-phonenum"]').val(workerInfo[4]);
	$('[name = "worker-branch"]').val(workerInfo[6]);
	$('[name = "worker-banknum"]').val(workerInfo[10]);
	$('[name = "worker-bank"]').val(workerInfo[11]);
	$('[name = "worker-entryday"]').val(workerInfo[7]);
	$('[name = "worker-leaveday"]').val(workerInfo[8]);
	$('[name = "worker-persionid"]').val(workerInfo[8]);
	
	editWorkerid = workerInfo[0];
}
//后台信息修改
function adminEdit(){
	var workerid = editWorkerid;
	var name = $('[name="worker-name"]').val();
	var birthday = $('[name = "worker-birthday"]').val();
	var email = $('[name = "worker-email"]').val();
	var branch = $('[name = "worker-branch"]').val();
	var phonenum = $('[name = "worker-phonenum"]').val();
	var banknum = $('[name = "worker-banknum"]').val();
	var bank = $('[name = "worker-bank"]').val();
	var entryday = $('[name = "worker-entryday"]').val();
	var leaveday = $('[name = "worker-leaveday"]').val();
	var persionid = $('[name = "worker-persionid"]').val();
	
	var dataArray = new Array(workerid,name,birthday,email,branch,phonenum,banknum,bank,entryday,leaveday,persionid);
	ajaxWorker("adminEdit",dataArray);
}
//后台管理
function adminPanel(){ajaxWorker("adminPanel",null)};
//个人附件获取
function selfFile(){ajaxWorker("viewFile",null)}
//个人信息获取
function selfInfo(){ajaxWorker("viewInfo",null)}
//个人附件上传
function enSelfFilePanel(){$("#div-mask-4").css("height",$(window).height()+'px');}
//取消附件上传
function disSelfFilePanel(){$("#div-mask-4").css("height",0)}
//删除已上传文件
function deleteSelfFile(filename){
	var dataArray = new Array(filename);
	ajaxWorker("deleteFile",dataArray);
}